package com.akupilih.app.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.akupilih.app.BeritaFragment;
import com.akupilih.app.R;
import com.akupilih.app.helper.DateHelper;

public class BeritaAdapter extends BaseAdapter {
	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater = null;

	public BeritaAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
		activity = a;
		data = d;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View vi = convertView;
		if (convertView == null)
			vi = inflater.inflate(R.layout.row_berita, null);
		TextView title = (TextView) vi.findViewById(R.id.b_title);
		TextView date = (TextView) vi.findViewById(R.id.b_date);
		TextView excerpt = (TextView) vi.findViewById(R.id.b_excerpt);
		HashMap<String, String> list = new HashMap<String, String>();
		list = data.get(position);
		title.setText(list.get(BeritaFragment.KEY_TITLE));
		date.setText(DateHelper.convertDate(list.get(BeritaFragment.KEY_DATE)));
		excerpt.setText(Html.fromHtml(list.get(BeritaFragment.KEY_EXCERPT)));
		return vi;
	}

}
